from core.response import StandardPagination
from file.models import TextVector
from rest_framework import serializers



class TextVectorSerializer(serializers.ModelSerializer):
    class Meta:
        model = TextVector
        fields = '__all__'


def get_by_file_id(file_id):
    text_vectors = TextVector.objects.filter(file_id=file_id)
    result = []
    if len(text_vectors) == 0:
        return result
    serializer = TextVectorSerializer(text_vectors, many=True)
    return serializer.data

def get_vectors_by_file_id(file_id, request):
    queryset = TextVector.objects.filter(file_id=file_id)
    paginator = StandardPagination()
    paginated_queryset = paginator.paginate_queryset(queryset,request)
    serializer = TextVectorSerializer(paginated_queryset, many=True)
    vectors_data = serializer.data
    return vectors_data,paginator

def delete_by_knowbase_id(knowbase_id):
    delete_count,delete_details = TextVector.objects.filter(know_base_id=knowbase_id).delete()
    return delete_count

def delete_by_file_id(file_id):
    delete_count,delete_details = TextVector.objects.filter(file_id=file_id).delete()
    return delete_count

